#coding=utf8

from django.db import models
from django.contrib import admin

# Create your models here.

#出版商
class Publisher(models.Model):
    name = models.CharField(max_length=30)
    address = models.CharField(max_length=50)
    city = models.CharField(max_length=60)
    state_province = models.CharField(max_length=30)
    country = models.CharField(max_length=50)
    website = models.URLField()

    def __unicode__(self):
        return self.name

#作者
class Author(models.Model):
    name = models.CharField('名字',max_length=60)
    avatar = models.URLField('头像',blank=True)
    intro = models.TextField('简介',blank=True,max_length=2000)

    def __unicode__(self):
        return self.name
#分类
class Category(models.Model):
    '''分类'''
    class Meta:
        verbose_name = '分类'
        verbose_name_plural = verbose_name
    title = models.CharField('分类名',max_length=80)
    parent = models.ForeignKey('self',blank=True)

    def __unicode__(self):
        return self.title


#图书
class Book(models.Model):
    '''电子书'''
    class Meta:
        verbose_name = '图书'
        verbose_name_plural = verbose_name
    isbn = models.CharField('ISBN',max_length=13,unique=True)
    title = models.CharField('书名',max_length=200)
    subtitle = models.CharField('副标题',max_length=200,blank=True)
    pages = models.IntegerField('页数',blank=True)
    author = models.CharField('作者',max_length=60)
#    author = models.ManyToManyField(Author)
    price = models.CharField('定价',max_length=60,blank=True)
    publisher = models.CharField('出版社',max_length=200,blank=True)
#    publisher = models.ForeignKey(Publisher)
    pubdate = models.CharField('出版日期',max_length=60,blank=True)
    cover_img = models.URLField('封面图',blank=True)
    summary = models.TextField('内容简介',blank=True,max_length=2000)
    author_intro = models.TextField('作者简介',blank=True,max_length=2000)

    def __unicode__(self):
        return self.title

#下载地址
class Download_link(models.Model):
    url = models.CharField('下载链接',max_length=250)
    book = models.ForeignKey(Book)
    type = models.CharField(max_length=100)
    digg = models.IntegerField('顶')
    digg_d = models.IntegerField('踩')

    def __unicode__(self):
        return self.url

class DownLinkInline(admin.StackedInline):
    model = Download_link
class DownLinkItemAdmin(admin.ModelAdmin):
    inlines = [DownLinkInline]


admin.site.register(Book,DownLinkItemAdmin)
admin.site.register(Download_link)
admin.site.register(Category)